import logging
import pandas as pd


logging.basicConfig()


# Define Function Percentile
def percentile(list, rsi):
    '''
    Calculating the value of Rsi_derivative
    :param list:
    :return:
    '''
    rsi_derivative = []
    for percentile in list:
        location = len(rsi) * percentile / 100.0
        loc_value = len(rsi) * percentile / 100
        if (location).is_integer() is True:
            derivative = (
                rsi[loc_value] +
                rsi[loc_value + 1]
            ) / 2
        else:
            derivative = rsi[int(loc_value)]
        rsi_derivative.append(derivative)
    return rsi_derivative


# Define the whole process
def rsi_derivative(path):
    df = pd.read_csv(path)
    data_origin = df.ix[0, 1:]
    rsi = sorted(data_origin)
    rsi_derivative = percentile(list, rsi)
    return rsi_derivative


path = ('/Users/kris_shen/Desktop/Python/monthForCal.csv')
list = [10, 20, 30, 40, 50, 60, 70, 80, 90]
rsi_derivative = rsi_derivative(path)


# Outputs
logging.error(rsi_derivative)